package logic

import (
	"context"
	"good_srv/models"

	"good_srv/good"
	"good_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品列表展示
func (l *GoodListLogic) GoodList(in *good.GoodListRequest) (*good.GoodListResponse, error) {
	// todo: add your logic here and delete this line
	var goods models.Good
	g := goods.List(in.Sort)
	var goodlists []*good.GoodList
	for _, i2 := range g {
		list := good.GoodList{
			Title:  i2.Title,
			Price:  i2.Price,
			Stock:  i2.Stock,
			TypeId: i2.TypeId,
			Soles:  i2.Soles,
			Image:  i2.Image,
			Status: i2.Status,
		}
		goodlists = append(goodlists, &list)
	}
	return &good.GoodListResponse{
		List: goodlists,
	}, nil
}
